#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <list>
using namespace std;

#define forn(i,n) for(int i=0;i<n;i++)
#define forall(it,X) for(typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
struct edge{
	edge(int f,int t,int c,int num=-1):from(f),to(t),cost(c),number(num){}
	edge(){}
	int from;
	int to;
	int cost;
	int number;
	bool operator<(edge& other){return cost<other.cost;}
	friend ostream& operator<<(ostream& out, const edge& e){out<<"("<<e.from<<","<<e.to<<","<<e.cost<<")";return out;}
};
typedef int node;
typedef list<edge> grafo;
typedef list<set<node> > lsn;

list<int> kruskal(grafo& g, int n){
	//devuelve la lista de los indices de los ejes del AGM
	lsn F; forn(i,n) F.push_back(set<node>()); int i=0;forall(it,F){it->insert(i);i++;}
	list<edge> S(g);
	list<int> res;
	while(!S.empty() && F.size()>1){
		grafo::iterator mins=S.begin();
		forall(e,S) if(*e<*mins) mins=e;
		
		lsn::iterator from=F.begin();
		while(from->count(mins->from)==0) from++;
		lsn::iterator to=F.begin();
		while(to->count(mins->to)==0) to++;
		
		if(from!=to){
			from->insert(to->begin(),to->end());
			F.erase(to);
			res.push_back(mins->number);
		}
		S.erase(mins);
	}
	return res;
}

bool conexo(grafo& g,int n){
	vector<list<node> > h(n);
	forall(it,g){
		h[it->from].push_back(it->to);
		h[it->to].push_back(it->from);
	}
	vector<bool> marke(n,false);
	queue<node> q;
	q.push(0);marke[0]=true;
	int marked=1;
	while(!q.empty()){
		int nod=q.front();q.pop();
		forall(vecino,h[nod]) if(!marke[*vecino]){
			q.push(*vecino);
			marke[*vecino]=true;
			marked++;
		}
	}
	return marked==n;
}

int costo(list<int> krus,grafo& g){
	int res=0;
	forall(ed,krus) forall(it,g) if(it->number==*ed) res+=it->cost;
	return res;
}

int main(){
	int cases;cin>>cases;
	forn(caso,cases){
		grafo g;
		int v,e; cin>>v>>e;
		forn(i,e){
			int from,to,cost;cin>>from>>to>>cost;
			g.push_back(edge(from-1,to-1,cost,i));
		}
		cout << "Case #"<<(caso+1)<<" : ";
		if(!conexo(g,v)) cout << "No way" << endl;
		else if(g.size()+1==v) cout << "No second way" << endl;
		else{
			int mincost=-1;
			list<int> agm=kruskal(g,v);
			forall(ed,agm){
				edge backup;
				forall(it,g) if(it->number==*ed){backup=*it;g.erase(it); break;}
				if(conexo(g,v)){
					int cuesta=costo(kruskal(g,v),g);
					if(cuesta<mincost||mincost<0) mincost=cuesta;
				}
				g.push_back(backup);
			}
			cout << mincost << endl;
		}
	}
	return 0;
}
